import request from "@/utils/request";

import type {
    userDate,
    blockOfRole,
    needIds,
} from "@/api/permission/role/type";
enum API {
    // 获取获取管理用户分页列表
    GET_USER_PAGE = "/admin/acl/user/",
    // 新增用户
    ADD_USER = "/admin/acl/user/save",
    // 修改用户
    UPDATE_USER = "/admin/acl/user/update",
    // 获取所有的职位和已有的职位
    GET_ALL_HAS = "/admin/acl/user/toAssign/",
    // 分配职位
    ASSIGN_ROLE = "/admin/acl/user/doAssignRole",
    // 按id删除
    DELETE_BY_ID = "/admin/acl/user/remove/",
    // 多删
    DELETE_MANY = "/admin/acl/user/batchRemove",
}

export const getUserPage = (page: number, limit: number,username:string) =>
    request.get<any, userDate>(API.GET_USER_PAGE + `${page}/${limit}/?username=${username}`);

export const addAndUpdateUser = (data: blockOfRole) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATE_USER, data);
    } else {
        return request.post<any, any>(API.ADD_USER, data);
    }
};

export const getAllHas = (adminId: number) => request.get<any, any>(API.GET_ALL_HAS + adminId);

export const assignRoles = (data: needIds) =>
    request.post<any, any>(API.ASSIGN_ROLE, data); 

export const deleteById = (id: number) => request.delete<any, any>(API.DELETE_BY_ID + id);

export const deleteMore = (idList:number[]) => request.delete<any,any>(API.DELETE_MANY, {data:idList})
